﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.IO;
using System.Xml.Serialization;

namespace LJLCommon.Helper
{
    public class XMLHelper
    {
        public static string Serialze<T>(T t)
        {
            using (StringWriter sw = new StringWriter())
            {
                XmlSerializer xs = new XmlSerializer(typeof(T));

                xs.Serialize(sw, t);

                sw.Close();
                sw.Dispose();

                return sw.ToString();
            }
        }

        public static T Deserialze<T>(string tStr)
        {
            using (StringReader sr = new StringReader(tStr))
            {
                XmlSerializer xs = new XmlSerializer(typeof(T));

                T t = (T)xs.Deserialize(sr);

                sr.Close();
                sr.Dispose();

                return t;
            }           
        }
    }
}
